package com.atstudy.set;

import java.util.Objects;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/3 10:23
 * @copyright: 博为峰
 */
public class Student implements Comparable {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    /*
       负整数   小于
       零      等于
       正整数   大于

       去重
       排序
    */
    @Override
    public int compareTo(Object o) {
        Student student = (Student) o;
//        System.out.println("student: " + student.getName());
//        System.out.println("this: " + this.getName());
        return this.name.compareTo(student.name);
    }
}
